package com.gxuwz.medical.web.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.gxuwz.medical.tools.LoginDao;
/**
 * 登录验证控制模块
 * @author 演示
 *
 */

public class LoginServlet extends BaseServlet {

	private static final Logger logger = LogManager.getLogger(LoginServlet.class);
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		login(request, response);
		
	}
	private void login(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String userid = request.getParameter("userid");
		String pwd = request.getParameter("pwd");
		response.setContentType("text/html; charset=gb2312");
		String path="error/404.jsp";
		
		try{
			LoginDao lg = new LoginDao();
			boolean a = lg.login(userid,pwd);
			if(a){
				path="index.jsp";
			        
			    }else{
			    	path="login.jsp";
			    }
		}catch(Exception e){
			e.printStackTrace();
			path="error/500.jsp";
		}
		    //跳转页面
		    process(request, response, path);
		
	}


}
